package com.buddy.lock.reentrantlock._01;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * 可重入锁
 * 使用ReentrantLock实现同步
 */
public class MyService {

    private Lock lock = new ReentrantLock();

    public void testMethod(){
        lock.lock();//调用ReentrantLock对象的lock()方法获取锁
        for (int i=0;i<5;i++){
            System.out.println("ThreadName="+Thread.currentThread().getName()+(" "+(i+1)));
        }
        lock.unlock();//unlock()释放锁
    }

}
